﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

public partial class OrderGenPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ItemsData.DataSource = Profile.ShoppingCart.GetAllCartItems();
            ItemsData.DataBind();
        }
    }
    protected void subButton_Click(object sender, EventArgs e)
    {
        if (Shipname.Text == "")
        {
            Response.Write("<script>alert('请输入姓名')</script>");
            return;
        }
        if (Address.Text == "")
        {
            Response.Write("<script>alert('请输入地址')</script>");
            return;
        }
        if (PhoneNumber.Text == "")
        {
            Response.Write("<script>alert('请输入电话号码')</script>");
            return;
        }

        Order order = new Order();
        try
        {
            order.AddOrders(Profile.UserName, Shipname.Text, Address.Text, PhoneNumber.Text, Profile.ShoppingCart);
            Profile.ShoppingCart.Clear();
            Profile.Save();
            
            Response.Write("<script>alert('生成订单成功');window.location.href='OrderPage.aspx';</script>");
            
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('生成订单失败: " + ex.Message + "')</script>");
        }
         
    }
    protected void backButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/CartPage.aspx");
    }
}